package org.lex.ftplist.ui.common;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import org.lex.ftplist.core.FtpUrl;

public class FtpUrlPane extends JPanel {
	private JCheckBox anonymousCheckBox;
	private JLabel hostLabel;
	private JTextField hostTextField;
	private JPasswordField passwordField;
	private JLabel passwordLabel;
	private JLabel pathLabel;
	private JTextField pathTextField;
	private JLabel portLabel;
	private JTextField portTextField;
	private JLabel userLabel;
	private JTextField userTextField;

	public FtpUrlPane() {
		initComponents();
	}

	public FtpUrl getUrl() {
		FtpUrl u = new FtpUrl();
		u.host = hostTextField.getText();
		u.port = Integer.parseInt(portTextField.getText());
		u.user = userTextField.getText();
		u.password = passwordField.getPassword();
		u.path = pathTextField.getText();
		return u;
	}

	private void initComponents() {
		GridBagConstraints gridBagConstraints;

		hostLabel = new JLabel("Host");
		portLabel = new JLabel("Port");
		hostTextField = new JTextField("localhost", 20);
		portTextField = new JTextField("21", 5);
		userLabel = new JLabel("User");
		userTextField = new JTextField("liuex", 10);
		passwordLabel = new JLabel("Password");
		pathLabel = new JLabel("Path");
		pathTextField = new JTextField("/", 20);
		anonymousCheckBox = new JCheckBox("anonymous");
		passwordField = new JPasswordField("liuex", 10);

		setLayout(new GridBagLayout());

		hostLabel.setName("hostLabel"); // NOI18N
		gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 0;
		gridBagConstraints.anchor = GridBagConstraints.WEST;
		gridBagConstraints.insets = new Insets(0, 0, 5, 5);
		add(hostLabel, gridBagConstraints);

		portLabel.setName("portLabel"); // NOI18N
		gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 1;
		gridBagConstraints.anchor = GridBagConstraints.WEST;
		gridBagConstraints.insets = new Insets(0, 0, 6, 6);
		add(portLabel, gridBagConstraints);

		hostTextField.setName("hostTextField"); // NOI18N
		gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.gridx = 1;
		gridBagConstraints.gridy = 0;
		gridBagConstraints.gridwidth = 2;
		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints.weightx = 1.0;
		gridBagConstraints.insets = new Insets(0, 0, 6, 0);
		add(hostTextField, gridBagConstraints);

		portTextField.setName("portTextField"); // NOI18N
		gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.gridx = 1;
		gridBagConstraints.gridy = 1;
		gridBagConstraints.gridwidth = 2;
		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints.weightx = 1.0;
		gridBagConstraints.insets = new Insets(0, 0, 6, 0);
		add(portTextField, gridBagConstraints);

		userLabel.setName("userLabel"); // NOI18N
		gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 2;
		gridBagConstraints.anchor = GridBagConstraints.WEST;
		gridBagConstraints.insets = new Insets(0, 0, 6, 6);
		add(userLabel, gridBagConstraints);

		userTextField.setName("userTextField"); // NOI18N
		gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.gridx = 1;
		gridBagConstraints.gridy = 2;
		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints.weightx = 1.0;
		gridBagConstraints.insets = new Insets(0, 0, 6, 0);
		add(userTextField, gridBagConstraints);

		passwordLabel.setName("passwordLabel"); // NOI18N
		gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 3;
		gridBagConstraints.anchor = GridBagConstraints.WEST;
		gridBagConstraints.insets = new Insets(0, 0, 6, 6);
		add(passwordLabel, gridBagConstraints);

		pathLabel.setName("pathLabel"); // NOI18N
		gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 4;
		gridBagConstraints.anchor = GridBagConstraints.WEST;
		gridBagConstraints.insets = new Insets(0, 0, 0, 6);
		add(pathLabel, gridBagConstraints);

		pathTextField.setName("pathTextField"); // NOI18N
		gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.gridx = 1;
		gridBagConstraints.gridy = 4;
		gridBagConstraints.gridwidth = 2;
		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints.weightx = 1.0;
		add(pathTextField, gridBagConstraints);

		anonymousCheckBox.setName("anonymousCheckBox");
		gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.gridx = 2;
		gridBagConstraints.gridy = 2;
		gridBagConstraints.insets = new Insets(0, 6, 6, 0);
		add(anonymousCheckBox, gridBagConstraints);

		passwordField.setName("passwordField");
		gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.gridx = 1;
		gridBagConstraints.gridy = 3;
		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints.weightx = 1.0;
		gridBagConstraints.insets = new Insets(0, 0, 6, 0);
		add(passwordField, gridBagConstraints);
	}
}
